﻿Imports HotelLibrary


Public Class _Default
    Inherits System.Web.UI.Page
    Dim ds As New DataSet
    Dim m_cust As New CustLib
    Dim loginCookie As New HttpCookie("Username")
    Dim custFunc As New CustomerFunction


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.Cookies("Username") Is Nothing Then
            lbl_Instructions.Text = "Please enter credentials if you are an existing user, or click 'Register New Account' if you need to create an account."
        Else
            Dim thisUsername As String = Request.Cookies("Username").Value
            txt_UserName.Text = thisUsername
            lbl_Instructions.Text = "Welcome " + thisUsername + ", please enter your password to login! If this is not your account, please enter your username and password."
        End If
    End Sub

    Protected Sub btn_Login_Click(sender As Object, e As EventArgs) Handles btn_Login.Click
        'check if userID is valid
        Dim sucess As Integer
        Dim userHash As String = custFunc.hashFunction(txt_UserName.Text.ToLower)
        Dim passHash As String = custFunc.hashFunction(txtPassword.Text)
        Dim hash As String = custFunc.hashFunction(userHash & passHash)
        'ds = custFunc.getCustomer(txt_UserName.Text)

        ' sucess = custFunc.chckCustomer(txt_UserName.Text, hash)

        If (sucess = 0) Then
            lblFeedback.Text = "Invalid User Name"
        Else
            If (sucess < 0) Then
                lblFeedback.Text = "Invalid Password"
            Else
                Response.Redirect("booking.aspx")
                Session.Add("username", txt_UserName.Text)
            End If
        End If
    End Sub

    Protected Sub btn_Register_Click(sender As Object, e As EventArgs) Handles btn_Register.Click
        
        Response.Redirect("Registration.aspx")

    End Sub

End Class